package com.cans.lightning.business.pms.service.impl;

import com.cans.lightning.base.mapper.IBaseMapper;
import com.cans.lightning.base.service.impl.BaseServiceImpl;
import com.cans.lightning.business.pms.dao.SysRoleDao;
import com.cans.lightning.business.pms.dto.SysRoleDto;
import com.cans.lightning.business.pms.entity.SysRole;
import com.cans.lightning.business.pms.mapper.SysRoleMapper;
import com.cans.lightning.business.pms.service.api.ISysRoleService;
import org.beetl.sql.core.page.DefaultPageRequest;
import org.beetl.sql.core.page.PageRequest;
import org.beetl.sql.core.page.PageResult;
import org.beetl.sql.mapper.BaseMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author shencan
 * @date 2020/6/14 20:53
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysRoleServiceImpl extends BaseServiceImpl<SysRole,SysRoleDto, String> implements ISysRoleService {

    @Resource
    private SysRoleDao sysRoleDao;
    @Resource
    private SysRoleMapper sysRoleMapper;


    @Override
    public BaseMapper<SysRole> getDaoImpl() {
        return sysRoleDao;
    }

    @Override
    public IBaseMapper<SysRole, SysRoleDto, String> getMapperImpl() {
        return sysRoleMapper;
    }

    @Override
    public PageResult<SysRoleDto> findPage(PageRequest<SysRole> pageRequest) {
        PageResult<SysRole> res = sysRoleDao.createLambdaQuery().page(pageRequest);
        PageRequest<SysRoleDto> pageRes = DefaultPageRequest.of(pageRequest.getPageNumber(),pageRequest.getPageSize());
        return pageRes.of(sysRoleMapper.toDtos(res.getList()),res.getTotalRow());
    }
}
